<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算数组的平均值</title>
    <style>
        *{
            padding:0;
            margin:0;
        }

        .box{
            color: white;
            background-color: orange;
            border-radius: 5px;
            width: 260px;
            padding:20px;
            margin:100px auto;
            font-family:'Arial', "Microsoft YaHei UI";
        }

        p{
            text-indent: 2em;
            line-height:25px;
            font-size: 14px;
        }
    </style>

    <script>
        window.onload = function () {
            var arrys = [78,59,12,46,78,21,35];

            var content = "";
            var sum = 0;
            for (var i = 0; i < arrys.length; i++) {
                var obj = arrys[i];
                sum +=obj;
                content += (obj+" ");
            }

            document.getElementsByTagName("p")[0].innerText = content;
            document.getElementsByTagName("span")[0].innerText = sum/arrys.length;
        }
    </script>
</head>
<body>
    <div class="box">
        <h3>数组内容:</h3>
        <p>这是数组中的内容</p>
        <h4>平均值: <span>123456</span></h4>
    </div>
</body>
</html>